<?php

namespace App\model;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\model\CustomerArea
 *
 * @property int $id
 * @property string|null $name
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int|null $sort
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereSort($value)
 * @property int|null $is_display
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\CustomerArea whereIsDisplay($value)
 */
class CustomerArea extends Model
{
    protected $table='customer_area';
    public static function getSelectOptions()
    {
        $options = \DB::table('customer_area')->select('id','name as text')->get();
        $selectOption = [];
        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }
    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('is_display', function (Builder $builder) {
            $builder->orderBy('sort','desc');
        });
    }
}
